package com.itheima.d7_interface_demo.interface_demo2;

import java.util.ArrayList;

public class StudentServiceimpl2 implements StudentService {


    @Override
    public void printAllInfo(ArrayList<Student> students) {//打印所有信息
        int boy = 0;
        int girl = 0;
        for (Student student : students) {
            System.out.println("姓名：" + student.getName() + " 性别：" + student.getSex() + " 成绩：" + student.getScore());
            if (student.getSex()=='男') {
                boy++;
            }else{
                girl++;
            }
        }
        System.out.println("男生人数："+boy+"  女生人数:"+girl);

        System.out.println("总人数是："+(boy+girl));
    }

    @Override
    public void printAverageScore(ArrayList<Student> students) {//打印平均分
        int sum = 0;
        double max=students.get(0).getScore();
        double min=students.get(0).getScore();
        for (Student student : students) {
            sum += student.getScore();
            if (max<student.getScore()){
                max = student.getScore();
            }
            if (min>student.getScore()){
                min = student.getScore();
            }

        }
        System.out.println("最高分是"+max);
        System.out.println("最低分是"+min);
        System.out.println("平均分是" + (sum-max-min) /( students.size()-2));
    }
}
